#include <iostream>
#include <sys/epoll.h>

const int g_num=128;
 const int g_timeout=4000;
class Epoll
{
    
public:
    Epoll(int num=g_num,int timeout=g_timeout)
    :_num(num)
    ,_timeout(timeout)
    {}
    void CreateEpoll()
    {
        _epofd=epoll_create(_num);
    }
    void AddSockToEpoll(int sock,uint32_t events)
    {   
        struct epoll_event ev;
        ev.events=events;
        ev.data.fd=sock;
        epoll_ctl(_epofd,EPOLL_CTL_ADD,sock,&ev);
    }
    void ModifyEpoll(int sock,uint32_t events)
    {
        struct epoll_event ep;
        ep.data.fd=sock;
        ep.events |=events;
        epoll_ctl(_epofd,EPOLL_CTL_MOD,sock,&ep);
    }
    void DeleteEpoll(int sock)
    {
        epoll_ctl(_epofd,EPOLL_CTL_DEL,sock,nullptr);
    }
    int WaitEpoll(struct epoll_event revs[],int num)
    {
        return epoll_wait(_epofd,revs,num,_timeout);    //这个返回值代表就绪事件的个数
    }
private:
    int _epofd;
    int _timeout;
    int _num;
};